<template>
    <div class="content">
        <div class="content-div">

            <div class="content-div-left">
                <div class="content-div-left-header">产品类型</div>
                <div class="content-div-left-item" v-for="item in catList" :key="item.id" @click="custom_cat_id=item.id; getProductList()">{{ item.title }}</div>
            </div>

            <div class="content-div-right">
                <div class="content-div-right-header">
                    <div>店铺主推商品</div>
                    <div class="content-div-right-tips" @click="$router.push('/companyInfo/product?shop_id='+$route.query.shop_id)">更多 ></div>
                </div>

                <div class="content-div-product"  v-if="productList.length > 0" >
                    <div class="content-div-product-item" v-for="item in productList" :key="item.id" @click="openDetail(item)">
                        <img :src="item.imageList[0]" alt="">
                        <div class="content-div-product-item-text">{{ item.title }}</div>
                    </div>  
                </div>
                <div class="nodata" v-if="productList.length == 0">暂无数据</div>
            </div>

        </div>

        <div class="company-profile">
            <div class="company-profile-name">公司简介</div>
            <div class="company-profile-tips">Company Introduction</div>
            <div class="company-profile-content">
                <img :src="detailData.company_logo_url" alt=""/>
                <div class="company-profile-content-txt">
                    <div>{{ detailData.company_introduction }}
                    </div>
                    <div class="company-profile-btn">查看更多<img src="@/static/engineering5188/company/arrow.png" alt=""/></div>
                </div>
            </div>
        </div>

        <div class="newProductClass">
            <div class="company-profile-name">最新产品</div>
            <div class="company-profile-tips">NEW products</div>

            <div class="newProductClass-content">
                <div class="arrowIconClass" @click="lastData()">
                    <img class="arrowIcon" src="@/static/engineering5188/company/left-arrow.png" alt="">
                </div>
                <div class="content-div-product-item" v-for="item in newProductList" :key="item.id" @click="openDetail(item)">
                    <img :src="item.imageList[0]" alt="">
                    <div class="content-div-product-item-text">{{ item.title }}</div>
                </div>
                <!-- <div class="content-div-product-item">
                    <img src="@/static/engineering5188/company/2.png" alt="">
                    <div class="content-div-product-item-text">材料名称-莱钢Q235H型钢 Q345bH型钢材金柱钢</div>
                </div> -->
                <div  class="arrowIconClassRight" @click="NextPage()">
                    <img  class="arrowIcon"  src="@/static/engineering5188/company/right-arrow.png" alt="">
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import { mapState } from "vuex";
export default {
    computed: {
        ...mapState([
            "userInfo",
        ]),
    },
    data() {
        return {
            detailData:null,
            productList:[],
            catList:[],
            custom_cat_id:undefined,
            newProductList:[],
            newPage:1,
            totalPage:1,
        }
    },
    created(){
        this.getDetail();
        this.getProductList();
        this.getCat();
        this.getNewProduct();
    },
    methods: {
        lastData(){
            if(this.newPage > 1){
                this.newPage--;
                this.getNewProduct();
            }
        },
        NextPage(){
            if(this.newPage < this.totalPage){
                this.newPage++;
                this.getNewProduct();
            }
        },
        openDetail(item){
          this.$router.push({
            path: '/companyInfo/product',
            query: {
              shop_id: item.shop_id,
              detail: true,
              id: item.id,
            }
          })
        },
        getNewProduct(){
            this.$httpApi("/api/getProductList", {
                shop_id: this.$route.query.shop_id,
                page: this.newPage,
                limit:5,
            }, "get").then(res =>{
                res.data.list.forEach(element => {
                    element.imageList = element.image.split(",");
                });
                this.newProductList = res.data.list;
                this.totalPage = Math.ceil(res.data.count / 10);
            })
        },
        getCat(){
            this.$httpApi("/api/getProductCustomCatList", {
                limit:10000,
                page:1,
                shop_id:this.$route.query.shop_id
            }, "get").then(res => {
                this.catList = res.data.list;
            })
        },
        getDetail(){
            this.$httpApi("/api/getShopDetail", {
                shop_id: this.$route.query.shop_id
            }, "get").then(res =>{
                this.detailData = res.data;
            })
        },
        getProductList(){
            this.$httpApi("/api/getProductList", {
                shop_id: this.$route.query.shop_id,
                page:1,
                limit:12,
                custom_cat_id:this.custom_cat_id,
            }, "get").then(res =>{
                res.data.list.forEach(element => {
                    element.imageList = element.image.split(",");
                });
                this.productList = res.data.list;
            })
        }
    },
}
</script>

<style scoped lang="less">
.content{
    padding-top: 20px;
    background: #F6F6F6;
    
}
.content-div{
   width: 1200px;
   margin: 0 auto;
   display: flex; 
   padding-bottom: 20px;
}
.content-div-left{
    width: 188px;
    flex-basis: 228px;
    flex-grow: 0;      /* 禁止放大 */
    flex-shrink: 0;    /* 禁止缩小 */
    background-color: #FFFFFF;
    margin-right: 20px;
    

    .content-div-left-header{
        background: #000000;
        height: 48px;
        line-height: 48px;
        text-align: center;
        font-weight: bold;
        font-size: 16px;
        color: #FFFFFF;
    }
    .content-div-left-item{
        height: 48px;
        line-height: 48px;
        margin-left: 20px;
        margin-right: 20px;
        font-weight: 500;
        font-size: 14px;
        color: #333333;
        border-bottom: 1px solid #E6E6E6;
        padding-left: 24px;
        cursor: pointer;
    }
}

.content-div-right{
    width: 100%;

    .content-div-right-header{
        height: 48px;
        background-color: #FFFFFF;
        font-weight: 500;
        font-size: 16px;
        color: #333333;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding-left: 24px;
        padding-right: 20px;
    }
    .content-div-right-tips{
        font-weight: 400;
        font-size: 14px;
        color: #999999;
        cursor: pointer;
    }
}

.content-div-product{
    margin-top: 10px;
    background-color: #FFFFFF;
    padding: 20px;
    padding-right: 0px;
    padding-top: 0px;
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;

    .content-div-product-item{
        width: 213px;
        height: 196px;
        border: 1px solid #E5E5E5;
        margin-right: 20px;
        margin-top: 20px;
        cursor: pointer;

        img{
            width: 100%;
            height: 130px;
        }

        .content-div-product-item-text{
            font-weight: 400;
            font-size: 14px;
            color: #000000;
            line-height: 22px;
            padding: 12px;
        }

    }
}

.company-profile{
    background-color: #fff;
    padding-top: 50px;
    padding-bottom: 62px;

    .company-profile-name{
        font-weight: 500;
        font-size: 36px;
        color: #0A0A0A;
        text-align: center;
    }
    .company-profile-tips{
        font-weight: 400;
        font-size: 16px;
        color: #999999;
        text-align: center;
        margin-top: 8px;
    }

    .company-profile-content{
        width: 1200px;
        margin: 0 auto;
        margin-top: 40px;
        display: flex;
        flex-direction: row;
        img{
            width: 468px;
            height: 343px;
            margin-right: 40px;
        }
        .company-profile-content-txt{
            font-weight: 400;
            font-size: 14px;
            color: #000000;
            line-height: 32px;
            text-align: left;
        }

        .company-profile-btn{
            width: 136px;
            height: 40px;
            border-radius: 24px 24px 24px 24px;
            border: 1px solid #333333;
            font-weight: normal;
            font-size: 14px;
            color: #333333;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-top: 27px;
            img{
                width: 23px;
                height: 15px;
                margin-left: 10px;
                margin-right: 0px;
            }
        }
    }
}

.newProductClass{
    padding-top: 40px;
    padding-bottom: 62px;

    .company-profile-name{
        font-weight: 500;
        font-size: 36px;
        color: #0A0A0A;
        text-align: center;
    }
    .company-profile-tips{
        font-weight: 400;
        font-size: 16px;
        color: #999999;
        text-align: center;
        margin-top: 8px;
    }

    .newProductClass-content{
        width: 1200px;
        margin: 0 auto;
        display: flex;
        position: relative;

        .content-div-product-item{
            width: 224px;
            height: 202px;
            border: 1px solid #E5E5E5;
            margin-right: 20px;
            margin-top: 20px;
            cursor: pointer;

            img{
                width: 100%;
                height: 136px;
            }

            .content-div-product-item-text{
                font-weight: 400;
                font-size: 14px;
                color: #000000;
                line-height: 22px;
                padding: 12px;
            }

        }
        .arrowIcon{
            width: 40px;
            height: 40px;
            cursor: pointer;
        }
        .arrowIconClass{
            position: absolute;
            top: 78px;
            left: -40px;
        }
        .arrowIconClassRight{
            position: absolute;
            top: 78px;
            right: -40px;
        }
    }
}

.nodata{
    height: 48px;
    background: #fff;
    margin-top: 10px;
    font-weight: 500;
    font-size: 16px;
    color: #333333;
    text-align: center;
    line-height: 48px;
}
</style>